package com.pig4cloud.pig.village.land.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.village.api.dto.LandDTO;
import com.pig4cloud.pig.village.api.dto.LandTotalDTO;
import com.pig4cloud.pig.village.api.entity.Land;
import com.pig4cloud.pig.village.land.service.ILandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author limbray.li
 * @date 2021/6/19
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/land-resource")
@Api(value = "land-resource", tags = "土地资源管理")
public class LandController {
	@Resource
	private ILandService landService;

	@GetMapping("/page")
	public R<IPage<LandDTO>> page(Integer pageNum, Integer pageSize, Long teamId, Long villagerId) {
		return R.ok(landService.selectForPage(new Page(pageNum, pageSize), teamId, villagerId));
	}

	@PostMapping("/update")
	public R update(@RequestBody Land land) {
		return R.ok(landService.updateById(land));
	}

	@GetMapping("/get")
	public R<LandDTO> get(Long id) {
		return R.ok(landService.getDtoById(id));
	}

	@PutMapping("/deleteById")
	public R delete(Long id) {
		return R.ok(landService.removeById(id));
	}

	@PostMapping("/add")
	public R add(@RequestBody Land land) {
		return R.ok(landService.save(land));
	}

	@GetMapping("/getTeamTotal")
	@ApiOperation("获取队内的总和")
	public R<List<LandTotalDTO>> getTeamTotal(Long teamId) {
		return R.ok(landService.teamTotal(teamId));
	}

	@GetMapping("/getVillageTotal")
	@ApiOperation("获取全村的总和")
	public R<LandTotalDTO> getVillageTotal() {
		return R.ok(landService.villageTotal());
	}
}
